import xadmin

from .models import Category,Article
from xadmin import views


#xadmin中这里是继承object，不再是继承admin
# class EmailVerifyRecordAdmin(object):
#     # 显示的列
#     list_display = ['code', 'email', 'send_type', 'send_time']
#     # 搜索的字段
#     search_fields = ['code', 'email', 'send_type']
#     # 过滤
#     list_filter = ['code', 'email', 'send_type', 'send_time']


# class BannerAdmin(object):
#     list_display = ['title', 'image', 'url','index', 'add_time']
#     search_fields = ['title', 'image', 'url','index']
#     list_filter = ['title', 'image', 'url','index', 'add_time']

class CategoryAdmin(object):
    list_display = ['parent','name','article_total']

xadmin.site.register(Category,CategoryAdmin)

class ArticleAdmin(object):
    list_display = ['title','project','category','html_content']
    readonly_fields =['user','add_time','update_time']
    style_fields = {"content": "ueditor"}#声明ueditor变量
    search_fields = ['title', 'content']
    # 过滤
    list_filter = ['category']
    
    def save_models(self):
        self.new_obj.user = self.request.user
        super().save_models()
xadmin.site.register(Article,ArticleAdmin)